﻿var starticons = []; //基站图标集合
var starticonPoints = []; //基站坐标集合
var popups = []; //弹出信息窗集合
var polylines = []; //基线集合
var i;
var j;

function GetBaseInfo() {
    var basechBox = document.getElementById("Checkbox3");
    if (basechBox.checked) {
        if (window.ActiveXObject) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else if (window.XMLHttpRequest) {
            xmlHttp = new XMLHttpRequest();
        }
        xmlHttp.onreadystatechange = BaseLinehandle;
        xmlHttp.open("GET", "GetBaseLine.aspx?r=", true);
        xmlHttp.send(null);
        dMap.addListener("click", function(point) {
            try {
//                                                alert(point);
                for (i = 0; i < starticons.length; i++) {
                    var B1 = starticonPoints[i].lat - 0.3;
                    var B2 = starticonPoints[i].lat;
                    var L1 = starticonPoints[i].lon;
                    var L2 = starticonPoints[i].lon + 0.2;
                    var B = point.lat;
                    var L = point.lon;
                    var bool1;
                    var bool2;
                    bool1 = ((eval(B1) < eval(B)) && (eval(B) < eval(B2)));
                    bool2 = ((eval(L1) < eval(L)) && (eval(L) < eval(L2)));
                    if (bool1 && bool2) {
                        popups[i].show(true);
                    }
                }
            }
            catch (e) { }
        })
    }
    else {
        if (starticons) {
            for (j = 0; j < starticons.length; j++)
                dMap.removeOverlay(starticons[j]);
            starticons.length = 0;
        }
        if (starticonPoints) {
            for (j = 0; j < starticonPoints.length; j++)
                dMap.removeOverlay(starticonPoints[j]);
            starticonPoints.length = 0;
        }
        if (polylines) {
            for (i = 0; i < polylines.length; i++)
                dMap.removeOverlay(polylines[i]);
            polylines.length = 0;
        }
        if (popups) {
            for (i = 0; i < popups.length; i++)
                dMap.removeOverlay(popups[i]);
            popups.length = 0;
        }
    }
}


function BaseLinehandle() {
    var BasexmlDom;
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            BasexmlDom = xmlHttp.responseXML;
            var Bases = BasexmlDom.documentElement.getElementsByTagName("Line");
            if (Bases[0] == null) {
                alert("无基站信息");
                return false;
            }
            var names = BasexmlDom.documentElement.getElementsByTagName("Name");
            for (var bn = 0; bn < names.length; bn++) {
                var nameB = parseFloat(names[bn].getAttribute("pointB"));
                var nameL = parseFloat(names[bn].getAttribute("pointL"));
                var namepoint = names[bn].getAttribute("pointName");
                var countpoint = parseInt(names[bn].getAttribute("count"));
                var citypoint = names[bn].getAttribute("basecity");
                var lonlat = new DLonLat(nameL, nameB);
                starticonPoints.push(lonlat);
                var addressID = parseFloat(names[bn].getAttribute("baseaddressID"));
                var bexist = (names[bn].getAttribute("bexist"));
                var imageaddress = "../themes/images/baseID_" + addressID + ".png";

                if (bexist == 'False')
                    imageaddress = "../themes/images/baseID_default.png";
                var config = { image: imageaddress };
                var starticon = new DIcon(lonlat, config);
                starticons.push(starticon);
                dMap.addOverlay(starticon);
                var poplonlat = new DLonLat(nameL, nameB);
                //事件处理
                var pop = null;
                var title = "<div style='margin-top:4px;font-size:10px;color:#000FFF;'>" + citypoint + "</div>";
                var content = "<div style='margin-top:4px;font-size:12px;color:green;'>" + namepoint + "</div>";
                var config = { color: "red", titleType: "html", flash: true, height: 20, width: 60 };
                if (!pop) {
                    pop = new DPopup(poplonlat, title, content, config);
                    popups.push(pop);
                    dMap.addOverlay(pop);
                }
                //                    pop.show(true);//显示基站信息文本框
            }
            for (var bi = 0; bi < Bases.length; bi++) {
                var BasemarkerPoints = "";
                var Drawline = null;
                var StartlineB = parseFloat(Bases[bi].getAttribute("BeginB"));
                var StartlineL = parseFloat(Bases[bi].getAttribute("BeginL"));
                var EndlineB = parseFloat(Bases[bi].getAttribute("EndB"));
                var EndlineL = parseFloat(Bases[bi].getAttribute("EndL"));

                BasemarkerPoints = StartlineL + "," + StartlineB + "," + EndlineL + "," + EndlineB;
                Drawline = new DPolyline(BasemarkerPoints, { color: "green", weight: 2, opacity: 0.8 });
                polylines.push(Drawline);
                dMap.addOverlay(Drawline);
            }

        }
    }

}